import { getToken, setToken, delToken } from "@/utils/storage";

//存token
const user = {
  namespaced: true,
  state: {
    //获取token
    token: getToken(),
  },
  //修改token
  mutations: {
    setUserToken(state, newToken) {
      //现在token给state
      state.token = newToken;
      //再把现在的存到本地
      setToken(newToken);
    },
    logout(state) {
      //清除state的token
      state.token = null;
      //清除本地储存
      delToken();
    },
  },
};

export default user;
